#include<iostream>
using namespace std;
typedef int Status;
typedef int ElemType;
int m; //m为操作次数
typedef struct LNode {
    ElemType data; //结点的数据域
    struct LNode *next; //结点的指针域
}LNode, *LinkList; //LinkList为指向结构体LNode的指针类型

void CreateList_R(LinkList &L, int n){// 后插
    L = new LNode;
    L->next = NULL;
    LNode *t = L;
    while(n--){
        LNode *p = new LNode;
        cin >> p->data;
        p->next = NULL;
        t->next = p;
        t = p;
    }
}

void MergeList_L(LinkList &LA, LinkList &LB, LinkList &LC){
    LC = new LNode;
    LC->next = NULL;
    LNode *pa = LA->next, *pb = LB->next, *t = LC;
    while(pa && pb){
        if(pa->data <= pb->data){
            t->next = pa;
            pa = pa->next;
        }else{
            t->next = pb;
            pb = pb->next;
        }
        t = t->next;
    }
    if(pa) t->next = pa;
    if(pb) t->next = pb;
    LA->next = NULL;
    LB->next = NULL;
}

void Out_list(LinkList L){//输出单链表
    LinkList p;
    p = L->next;
    while (p){
        cout <<p->data<<' ';
        p = p->next;
    }
    cout<<endl;
}

int main() {
    LinkList LA,LB,LC;
    int j,k;
    cin >> m;     //m次操作
    while(m --) {
        char op;
        cin >> op;
        switch(op){
            case 'A'://创建链式有序表LA
                cin>>j;
                CreateList_R(LA, j);
                Out_list(LA);
                break;
            case 'B'://创建链式有序表LB
                cin>>k;
                CreateList_R(LB, k);
                Out_list(LB);
                break;
            case 'M'://合并顺序有序表
                MergeList_L(LA, LB, LC);
                Out_list(LC);
                break;
        }
    }
    return 0;
}
